<template>
    <div class="app-container goodmy">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px">
            <el-form-item label="SPU编码" prop="spuNo">
                <el-input v-model="queryParams.spuNo" onkeyup="this.value=this.value.replace(/[^A-Z0-9\-]/g,'');" placeholder="请输入SPU编码" clearable size="small" />
            </el-form-item>
            <el-form-item label="SKU编码" prop="skuNo">
                <el-input v-model="queryParams.skuNo" onkeyup="this.value=this.value.replace(/[^A-Z0-9\-]/g,'');" placeholder="请输入SKU编码" clearable size="small" />
            </el-form-item>
            <el-form-item label="商品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" onkeyup="this.value=this.value.replace(/[[+]/g,'').replace(/[\]+]/g,'');" placeholder="请输入商品名称" clearable size="small" />
            </el-form-item>

            <el-form-item label="商品货号" prop="goodsModel">
                <el-input v-model="queryParams.goodsModel" onkeyup="this.value=this.value.replace(/[^A-Z0-9\-]/g,'');" placeholder="请输入商品货号" clearable size="small" />
            </el-form-item>

            <el-form-item label="价格" prop="priceStart">
                <el-input v-model="queryParams.priceStart" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" placeholder="请输入价格" clearable size="small" />
            </el-form-item>
            <p class="xian"></p>
            <el-form-item prop="priceEnd">
                <el-input v-model="queryParams.priceEnd" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" placeholder="请输入价格" clearable size="small" />
            </el-form-item>
            <el-form-item label="商品品牌" prop="brandName">
                <el-select class="select" v-model="queryParams.brandName" allow-create filterable default-first-option placeholder="请选择品牌">
                    <el-option v-for="(item, index) in brandOptions" :key="index" :label="item.name" :value="item.name"> </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="品类" prop="categoryNo">
                <el-select v-model="queryParams.categoryNo" placeholder="请输入品类">
                    <el-option v-for="(item, index) in selectCategory" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-col :span="1.5">
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                </el-col>
                <el-col :span="1.5" style="margin-left: 20px;">
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-col>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :headers="headers" v-hasPermi="['biz:shop:export']">导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="synchronization()" dialogTableVisible="true">同步</el-button>
            </el-col>
            <!--        </el-col>-->
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="batchRemove" dialogTableVisible="true">批量删除</el-button>
            </el-col>

            <el-col :span="1.5">
                <el-button :icon="priceIcon" size="mini" @click="resetMoney">价格</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button :icon="saleIcon" size="mini" @click="resetNumber">销量</el-button>
            </el-col>

            <el-col :span="1.5">
                <el-button icon="el-icon-reading" size="mini" @click="syncLog">商品的同步日志</el-button>
            </el-col>
            <!--            <el-col :span="1.5">-->
            <!--                <el-button :icon="stock" size="mini" @click="onStock">库存</el-button>-->
            <!--            </el-col>-->
            <!--            <el-col :span="1.5">-->
            <!--                <el-button :icon="time" size="mini" @click="onTime">时间</el-button>-->
            <!--            </el-col>-->
            <el-radio-group v-model="queryParams.wareHouseType" class="radio" size="medium" style="float: right;" @change="handleQuery" text-color>
                <el-radio-button label="国内现货"></el-radio-button>
                <el-radio-button label="欧洲现货"></el-radio-button>
                <el-radio-button label="香港现货"></el-radio-button>
            </el-radio-group>
        </el-row>
        <el-table :data="goodsList" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="30"> </el-table-column>
            <el-table-column type="expand">
                <template slot-scope="props">
                    <el-form label-position="left" inline class="demo-table-expand">
                        <el-form-item class="title" label="等级分类" style="display: block;"> </el-form-item>
                        <el-form-item label="一级分类" class="title_b">
                            <span>{{ props.row.categoryName1 }}</span>
                        </el-form-item>
                        <el-form-item label="二级分类" class="title_b">
                            <span>{{ props.row.categoryName2 }}</span>
                        </el-form-item>
                        <el-form-item label="三级分类" class="title_b">
                            <span>{{ props.row.categoryName3 }}</span>
                        </el-form-item>
                        <el-form-item class="title" label="价格" style="display: block;"> </el-form-item>
                        <el-form-item label="商品采购价" class="title_b">
                            <span>{{ props.row.purchasePrice }}</span>
                        </el-form-item>
                        <el-form-item label="市场参考价" class="title_b">
                            <span>{{ props.row.marketPrice }}</span>
                        </el-form-item>
                        <el-form-item label="欧洲专柜价" class="title_b">
                            <span>{{ props.row.euSalesPrice }}</span>
                        </el-form-item>
                        <el-form-item label="一般贸易税" class="title_b">
                            <span>{{ props.row.tradePriceTax }}</span>
                        </el-form-item>
                        <el-form-item label="跨境税" class="title_b">
                            <span>{{ props.row.crossBorderTax }}</span>
                        </el-form-item>
                        <el-form-item label="一般贸易运费" class="title_b">
                            <span>{{ props.row.tradePriceFreight }}</span>
                        </el-form-item>
                        <el-form-item label="跨境运费" class="title_b">
                            <span>{{ props.row.crossBorderFreight }}</span>
                        </el-form-item>
                        <el-form-item label="香港取货运费" class="title_b">
                            <span>{{ props.row.hkDeliveryPrice }}</span>
                        </el-form-item>
                        <el-form-item class="title" label="库存" style="display: block;"> </el-form-item>
                        <el-form-item label="国内现货数" class="title_b">
                            <span>{{ props.row.domesticStock }}</span>
                        </el-form-item>
                        <el-form-item label="香港现货数" class="title_b">
                            <span>{{ props.row.hkStock }}</span>
                        </el-form-item>
                        <el-form-item label="欧洲现货数" class="title_b">
                            <span>{{ props.row.euStock }}</span>
                        </el-form-item>
                        <el-form-item label="总库存数" class="title_b">
                            <span>{{ props.row.totalStock }}</span>
                        </el-form-item>
                    </el-form>
                </template>
            </el-table-column>
            <el-table-column label="图片" width="130">
                <template slot-scope="scope">
                    <el-image class="imgs" style="width: 100px; height: 100px" :src="scope.row.mainImgUrl" :preview-src-list="scope.row.detailImgSet"> </el-image>

                    <!--                    <img :src="scope.row.mainImgUrl" width="40" height="40" />-->
                    <!-- <img :src="z" width="40" height="40" /> -->
                </template>
            </el-table-column>
            <el-table-column label="品牌" prop="brandName"></el-table-column>
            <el-table-column label="名称" prop="goodsName"> </el-table-column>
            <el-table-column label="货号" prop="goodsModel"> </el-table-column>
            <el-table-column label="SPU编码" prop="goodsNo"> </el-table-column>
            <el-table-column label="SKU编码" prop="skuNo"> </el-table-column>
            <el-table-column label="规格" prop="spec"> </el-table-column>
            <el-table-column label="已同步的店铺" prop="syncStops"> </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <!-- <img :src="scope.row.mainImgUrl" width="40" height="40" /> -->
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">详情</el-button>
                    <el-button size="mini" type="text" icon="el-icon-lock" @click="lockGoods(scope.row)">{{ scope.row.lockStatus }}</el-button>

                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">移除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--  -->
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改店铺对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" label-width="100px">
                <div class="flex">
                    <el-form-item label="品牌名称" prop="brandName">
                        <el-input v-model="form.brandName" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="商品名称" prop="goodsName">
                        <el-input v-model="form.goodsName" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="商品货号" prop="brandNo">
                        <el-input v-model="form.goodsModel" :disabled="readonly" />
                    </el-form-item>
                </div>
                <div class="flex">
                    <el-form-item label="一级分类" prop="brandName">
                        <el-input v-model="form.categoryName1" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="二级分类" prop="goodsName">
                        <el-input v-model="form.categoryName2" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="三级分类" prop="brandNo">
                        <el-input v-model="form.categoryName3" :disabled="readonly" />
                    </el-form-item>
                </div>

                <div class="flex">
                    <el-form-item label="产地" prop="brandName">
                        <el-input v-model="form.areaRaw" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="规格" prop="totalStock">
                        <el-input v-model="form.spec" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="材质" prop="goodsName"
                        ><!--no-->
                        <el-input v-model="form.materialRaw" :disabled="readonly" />
                    </el-form-item>
                </div>

                <div class="flex">
                    <el-form-item label="商品采购价" prop="goodsName">
                        <el-input v-model="form.purchasePrice" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="市场参考价" prop="brandNo">
                        <el-input v-model="form.marketPrice" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="建议零售价" prop="totalStock">
                        <el-input v-model="form.retailPrice" :disabled="readonly" />
                    </el-form-item>

                    <!--                    <el-form-item label="建议零售价" prop="brandNo">-->
                    <!--                        <el-input v-model="form.marketPrice" :disabled="readonly" />-->
                    <!--                    </el-form-item>-->
                </div>
                <div class="flex">
                    <el-form-item label="欧洲专柜价" prop="brandName">
                        <el-input v-model="form.euSalesPrice" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="香港交货价" prop="brandName">
                        <el-input v-model="form.hkDeliveryPrice" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="spu编号" prop="goodsNo">
                        <el-input v-model="form.goodsNo" :disabled="readonly" />
                    </el-form-item>

                    <!--                    <el-form-item label="一般贸易价" prop="goodsName">-->
                    <!--                        <el-input v-model="form.categoryName1" :disabled="readonly" />-->
                    <!--                    </el-form-item>-->
                </div>
                <div class="flex">
                    <el-form-item label="sku编号" prop="skuNo">
                        <el-input v-model="form.skuNo" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="一般贸易运费" prop="tradePriceFreight">
                        <el-input v-model="form.tradePriceFreight" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="一般贸易税" prop="tradePriceTax">
                        <el-input v-model="form.tradePriceTax" :disabled="readonly" />
                    </el-form-item>
                </div>

                <div class="flex">
                    <el-form-item label="跨境BC运费" prop="brandNo">
                        <el-input v-model="form.crossBorderFreight" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="跨境BC税" prop="brandNo">
                        <el-input v-model="form.crossBorderTax" :disabled="readonly" />
                    </el-form-item>

                    <el-form-item label="总库存" prop="totalStock">
                        <el-input v-model="form.totalStock" :disabled="readonly" />
                    </el-form-item>
                </div>
                <div class="flex">
                    <el-form-item label="国内现货数" prop="totalStock">
                        <el-input v-model="form.domesticStock" :disabled="readonly" />
                    </el-form-item>
                    <el-form-item label="香港现货数" prop="skuNo">
                        <el-input v-model="form.hkStock" :disabled="readonly" />
                    </el-form-item>

                    <el-form-item label="欧洲现货数" prop="totalStock">
                        <el-input v-model="form.euStock" :disabled="readonly" />
                    </el-form-item>
                </div>
            </el-form>
            <!-- <div slot="footer" class="dialog-footer">
 <el-button type="primary" @click="submitForm">确 定</el-button>
 <el-button @click="cancel">取 消</el-button>
</div> -->
            <div class="goodImages">
                <p class="imgTitle">图片</p>
                <p v-if="form.detailImgSet !== undefined && form.detailImgSet.length == 0">暂无图片</p>
                <img class="goodImg" :src="item" alt="" v-for="(item, index) in form.detailImgSet" :v-key="index" />
            </div>
        </el-dialog>

        <el-dialog :title="locktitle" :visible.sync="lockopen" width="700px" append-to-body>
            <el-form ref="lockform" :model="lockform" :rules="rules" label-width="100px">
                <el-form-item label="锁定数量" prop="lockNum">
                    <el-input v-model="lockform.lockNum" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" />
                </el-form-item>
                <div class="flex">
                    <el-form-item label="锁定截止时间" prop="endTime" label-width="120">
                        <el-date-picker clearable size="small" style="width: 214px" v-model="lockform.endTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择营业期限"> </el-date-picker>
                    </el-form-item>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="applyLock">确 定</el-button>
                <el-button @click="lockcancel">取 消</el-button>
            </div>
        </el-dialog>
        <el-dialog :visible.sync="dialogTableVisible" width="400px">
            <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelect">
                <el-table-column type="selection" width="50"> </el-table-column>
                <el-table-column prop="name" label="平台名称" width="120"> </el-table-column>
                <el-table-column prop="address" label="店铺名称" show-overflow-tooltip> </el-table-column>
            </el-table>
            <el-button type="primary" class="confirm" @click="syncGoods">确认</el-button>
        </el-dialog>



        <el-dialog class="el-dialog-div" width="1300px" style="height: 100%;" title="同步记录" :visible.sync="synckuang">
            <div class="el-dialog-div">
                <el-table :data="reqlistdata.records">
                    <el-table-column prop="content" label="同步状态" width="150"></el-table-column>
                    <el-table-column prop="goodsId" label="商品sku" width="150"></el-table-column>
                    <el-table-column prop="goodsInfo.shopName" label="同步店铺" width="150"></el-table-column>
                    <el-table-column prop="createdTime" label="同步时间" width="160"></el-table-column>
                    <el-table-column prop="reponseData" label="同步结果" ></el-table-column>

                </el-table>

                <pagination layout="prev, pager, next" v-show="reqlistdata.total > 0" :total="reqlistdata.total" :page.sync="thisdatas.current" :limit.sync="reqlistdata.size" @pagination="getSyncGoodsLists" />
            </div>
        </el-dialog>

    </div>
</template>

<script>
import { listGoods, getGoods, syncGoodsToStop, goodsLock, deleteGoods, exportShop,exportGoods, deleteGoodsBatch,getSyncLog } from '@/api/biz/goods';
import { getToken } from '@/utils/auth';

export default {
    name: 'Shop',
    data() {
        return {
            priceIcon: 'el-icon-top',
            saleIcon: 'el-icon-top',
            // 按钮组
            drawer: false,
            headers: {
                Authorization: 'Bearer ' + getToken()
            },
            direction: 'ttb',
            isdisabledFn: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            skuNoLists: [],
            shops: [],
            // 非单个禁用
            single: true,
            readonly: true,
            // 非多个禁用
            multiple: true,
            // 总条数
            total: 0,
            // 店铺表格数据
            goodsList: [],
            // 弹出层标题
            title: '',
            synckuang:false,
            // 状态字典
            statusOptions: [],
            maoyiOptions: [],
            platOptions: [],
            catogeryOptions: [
                {
                    name: '选项一',
                    id: 1
                },
                {
                    name: '选项二',
                    id: 2
                }
            ],

            // 是否显示弹出层
            open: false,
            lockopen: false,
            locktitle: '',
            // 查询参数
            queryParams: {
                pageNo: 1,
                pageSize: 10,
                spuNo: undefined,
                skuNo: undefined,
                goodsName: undefined,
                brandName: undefined,
                goodsModel: undefined,
                categoryNo: undefined,
                priceStart: undefined,
                priceEnd: undefined,
                priceSort: undefined,
                salesSort: undefined,
                shopID: this.$store.state.user.shopid,
                wareHouseType: undefined
            },
            // 表单参数
            form: {},
            reqlistdata:[],
            thisdatas: {
                current: undefined,
                skuNo: undefined
            },
            lockform: {
                skuNo: undefined,
                lockNum: undefined,
                startTime: undefined,
                endTime: undefined,
                spuNo: undefined
            },
            // 表单校验

            rules: {
                lockNum: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
                // startTime: [
                //     {
                //         required: true,
                //         message: "开始时间不能为空",
                //         trigger: "blur"
                //     }
                // ],
                endTime: [
                    {
                        required: true,
                        message: '截止时间不能为空',
                        trigger: 'blur'
                    }
                ]
            },
            radio: '国内现货', // 货源
            dialogTableVisible: false,
            //   列表
            tableData: [],
            multipleSelection: [],
            selectCategory: [],
            brandOptions: [],
            // 数据
            tableData: [],
            z: require('../../../assets/image/profile.jpg'),
            multipleSelection: [], // 多选框
            stock: '',
            time: ''
        };
    },
    created() {
        this.getList();
        this.getUrl('/goods/getCategoryBrandList').then(response => {
            this.brandOptions = response.data;
        });

        this.getUrl('/goods/getShopCategoryList').then(response => {
            if (response.code == 200) {
                this.selectCategory = response.data;
            }
        });

        this.getUrl('/web/getshoplist').then(response => {
            if (response.code == 200) {
                response.data.forEach((item, index) => {
                    if (item.plat == 3) {
                        this.tableData.push({
                            id: item.id,
                            name: '考拉',
                            address: item.name
                        });
                    }

                    if (item.plat == 4) {
                        this.tableData.push({
                            id: item.id,
                            name: '寺库',
                            address: item.name
                        });
                    }
                });
            }
        });
    },
    methods: {
        resetMoney() {
            if (this.priceIcon == 'el-icon-bottom') {
                this.priceIcon = 'el-icon-top';
                this.queryParams.priceSort = 2;
            } else {
                this.priceIcon = 'el-icon-bottom';
                this.queryParams.priceSort = 1;
            }
            this.getList();
        },
        resetNumber() {
            if (this.saleIcon == 'el-icon-bottom') {
                this.saleIcon = 'el-icon-top';
                this.queryParams.salesSort = 2;
            } else {
                this.saleIcon = 'el-icon-bottom';
                this.queryParams.salesSort = 1;
            }
            this.getList();
        },
        // 库存排序
        onStock() {
            if (this.stock == 'el-icon-bottom') {
                this.stock = 'el-icon-top';
                // this.queryParams.salesSort = 2;
            } else {
                this.stock = 'el-icon-bottom';
                // this.queryParams.salesSort = 1;
            }
            this.getList();
        },
        // 时间排序
        onTime() {
            if (this.time == 'el-icon-bottom') {
                this.time = 'el-icon-top';
                // this.queryParams.salesSort = 2;
            } else {
                this.time = 'el-icon-bottom';
                // this.queryParams.salesSort = 1;
            }
            this.getList();
        },
        syncshop() {
            if (this.ids.length > 0 && this.shops.length > 0) {
            }
        },
        /** 查询店铺列表 */
        getList() {
            this.loading = false;
            this.queryParams.shopID = localStorage.nn;
            setTimeout(() => {
                if (localStorage.nn) {
                    listGoods(this.queryParams, 2)
                        .then(response => {
                            if (typeof response.data == 'undefined') {
                                this.goodsList = [];
                                this.total = 0;
                            }
                            var resData = response.data;
                            if (resData.code == 0) {
                                this.goodsList = resData.content;
                                this.total = resData.total;
                                this.goodsList.forEach(element => {
                                    element.detailImgSet = element.detailImgSet.split(',');
                                    element.detailImgSet.push(element.mainImgUrl);
                                    //console.log(element.detailImgSet);
                                });
                            }

                            this.loading = false;
                        })
                        .catch(e => console.log(e)); //捕获异常;
                } else {
                    this.$message.error('请添加店铺后，再次尝试。');
                }
            }, 50);
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 取消按钮
        lockcancel() {
            this.lockopen = false;
        },
        // 表单重置
        reset() {
            this.form = {
                id: undefined,
                uid: undefined,
                plat: undefined,
                name: undefined,
                appKey: undefined,
                appSecret: undefined,
                tradefrom: undefined,
                jycategory: [],
                jypipai: [],
                createdTime: undefined,
                status: '0'
            };
            this.resetForm('form');
        },
        /** 搜索按钮操作 */
        handleQuery() {
            if (this.queryParams.wareHouseType == '全部') {
                this.queryParams.wareHouseType = 0;
            }
            if (this.queryParams.wareHouseType == '国内现货') {
                this.queryParams.wareHouseType = 2;
            }
            if (this.queryParams.wareHouseType == '欧洲现货') {
                this.queryParams.wareHouseType = 1;
            }
            if (this.queryParams.wareHouseType == '香港现货') {
                this.queryParams.wareHouseType = 3;
            }
            this.queryParams.pageNo = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.wareHouseType = 0;
            this.queryParams.salesSort = 0;
            this.queryParams.priceSort = 0;
            this.resetForm('queryForm');
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            const temp = [];
            selection.forEach(function(item, index) {
                temp.push(item.skuNo);
                // this.skuNoLists.push(item.skuNo);
            });
            this.skuNoLists = temp;
            // console.log(this.skuNoLists)
            this.ids = selection.map(item => item.skuNo);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },

        // 多选框选中数据
        handleSelect(selection) {
            this.shops = selection.map(item => item.id);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            console.log(row);

            this.reset();
            const skuNo = row.skuNo;
            getGoods(skuNo).then(response => {
                var resData = response.data;
                console.log(resData);

                if (resData.code == 0) {
                    this.form = resData.content;

                    if (this.form.detailImgSet != null) {
                        this.form.detailImgSet = this.form.detailImgSet.split(',');
                        //this.form.detailImgSet.push(this.form.mainImgUrl);
                    } else {
                        this.form.detailImgSet = [];
                        //this.form.detailImgSet.push(this.form.mainImgUrl);
                    }
                }

                this.open = true;
                this.title = '商品详情';
            });
        },
        //同步商品
        syncGoods() {
            if (this.ids.length < 1 || this.shops.length < 1) {
                return;
            }
            var goods = this.ids.join(',');
            var shopids = this.shops.join(',');
            this.loading = true;
            syncGoodsToStop(shopids, goods).then(response => {
                this.loading = false;
                if (response.code === 200) {
                    this.dialogTableVisible = false;
                    this.msgSuccess(response.msg);
                    this.getList();
                } else {
                    this.msgError('系统繁忙');
                }
            });
        },

        applyLock() {
            var shopId = this.$store.state.user.shopid;
            if (!shopId) {
                return "请选择店铺";
            }
            this.lockform.shopId = shopId;
            this.$refs['lockform'].validate(valid => {
                if (valid) {
                    if (this.lockform.lockNum <= 0) {
                        this.msgError('锁库数量错误');
                        return false;
                    }
                    if (this.lockform.lockNum > 100000000) {
                        this.msgError('锁库数量错误');
                        return false;
                    }
                    if (this.lockform.skuNo != undefined) {
                        goodsLock(this.lockform).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess('ok,锁库待审核');
                                this.lockopen = false;
                                this.getList();
                            } else {
                                this.msgError('error');
                            }
                        });
                    }
                }
            });
        },
        // 状态字典翻译
        statusFormat(row, column) {
            return this.selectDictLabel(this.statusOptions, row.status);
        },
        /** 提交按钮 */
        submitForm: function() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    if (this.form.id != undefined) {
                        updateShop(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess('修改成功');
                                this.open = false;
                                this.getList();
                            } else {
                                this.msgError(response.msg);
                            }
                        });
                    } else {
                        this.form.then(response => {
                            if (response.code === 200) {
                                this.msgSuccess('新增成功');
                                this.open = false;
                                this.getList();
                            } else {
                                this.msgError(response.msg);
                            }
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        lockGoods(row) {
            console.log(row);
            const ids = row.id || this.ids;
            this.lockform.skuNo = row.skuNo;
            this.lockform.lockNum = undefined;
            this.lockform.endTime = undefined;

            this.locktitle = '锁定库存';
            this.lockform.spuNo = row.goodsNo;
            if (row.lockStatus == '锁定中' || row.lockStatus == '锁定审核中') {
                this.lockopen = false;
            } else {
                this.lockopen = true;
            }
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            // console.log(row);
            const ids = row.skuNo;
            this.$confirm('是否移除该商品吗?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(function() {
                    return deleteGoods(ids);
                })
                .then(() => {
                    this.getList();
                    this.msgSuccess('删除成功');
                })
                .catch(function() {});
        },

        /** 导出按钮操作 */
        handleExport() {
            const skuNoLists = this.skuNoLists;
            if (skuNoLists.length < 1) {
                this.msgError('您未选择数据');
                return;
            }
            this.$confirm('是否确认导出所选数据项?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(function() {
                    return exportGoods(skuNoLists.join(','));
                })
                .then(response => {
                    //this.download(response.msg);
                    this.msgSuccess(response.msg);
                })
                .catch(function() {});
        },
        // 同步_显示弹窗
        synchronization() {
            if (this.ids.length != 0) {
                this.dialogTableVisible = true;
            }
        },

        syncLog(){
            this.getSyncGoodsLists();
            this.synckuang = true;

        },
        getSyncGoodsLists: function() {
            getSyncLog(this.thisdatas).then(response => {
                if (response.code == 200) {
                    this.reqlistdata = response.data;
                    this.reqlistdata.records.forEach(item => {
                        item.createdTime = item.createdTime.replace("T"," ");
                    })
                }
            });
        },

        batchRemove(){
            const skuNoLists = this.skuNoLists;
            if (skuNoLists.length == 0) {
                this.msgError('您未选择数据');
                return;
            }
            this.$confirm('是否移除所选商品吗?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(function() {
                    return deleteGoodsBatch(skuNoLists);
                })
                .then(() => {
                    this.getList();
                    this.msgSuccess('删除成功');
                })
                .catch(function() {});
        }
    },
    watch: {
        '$store.state.user.shopid': function(newFlag, oldFlag) {
            // 需要执行的代码
            this.queryParams.shopID = this.$store.state.user.shopid;
            this.getList();
        }
    }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.xian {
    width: 20px;
    height: 1px;
    margin: 18px 5px 0 0 !important;

    background: #333333;
    display: inline-block;
}
.radio {
    margin-right: 3px;
}
.imgTitle {
    color: #333333;
    font-size: 16px;
    line-height: 16px;
}
.images {
    display: flex;
}
.images img {
    margin: 10px;
    flex: 1;
}
.confirm {
    display: block;
    margin: 25px auto 0 auto;
}
/* 表格 */
.demo-table-expand {
    font-size: 0;
}
.demo-table-expand label {
    width: 100px;
    color: #99a9bf;
}
.demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 20%;
}

.goodmy .title {
    margin-bottom: 8px;
}
.goodmy .title_b label,
.goodsall .title_b div {
    font-size: 12px !important;
}
.goodmy .title label {
    font-size: 16px;
    line-height: 16px;
    color: #333;
    font-weight: 400;
    margin: 10px 0;
}
.goodmy .el-table__expanded-cell {
    padding: 20px 50px 20px 90px !important;
}
.goodImages {
    overflow: hidden;
    margin-left: 60px;
    .imgTitle {
        text-align: right;
        vertical-align: middle;
        float: left;
        font-size: 14px;
        color: #606266;
        box-sizing: border-box;
        line-height: 36px;
        font-weight: 600;
        margin: 5px 0;
    }
    .imgTitle + div {
        overflow: hidden;
    }
    .goodImg {
        float: left;
        margin: 15px;
        width: 100px;
        height: 100px;
    }
}
.imgs img {
    width: 100%;
    height: 100%;
}
</style>
